const http = require('../../../utils/util')
const Base64 = require('../../../utils/base')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        page: 1,
        helpList: []
    },

    getList: function () {
        const _this = this
        let data = {
            user_id: wx.getStorageSync('user_id'),
            user_token: wx.getStorageSync('user_token'),
            page: _this.data.page
        }
        http.post('help/help',Base64.encode(JSON.stringify(data))).then(res => {
            console.log(res)
            if(res.status == 1) {
                if(_this.data.page > 1) {
                  _this.setData({
                    helpList: [..._this.data.helpList,...res.result]
                  })
                } else {
                  _this.setData({
                    helpList: res.result
                  })
                }
              } else {
                // if (_this.data.page > 1) {
                //   _this.setData({
                //     page: --_this.data.page
                //   })
                // }
              }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getList()
    },

    helpDetails: function (e) {
        wx.navigateTo({
            url: '/pages/mine/help/helpdetails/helpdetails?id=' + e.currentTarget.dataset.id
          })
    },
    onReachBottom: function () {
        if(this.data.helpList.length != 0 && this.data.helpList.length % 10 == 0) {
          this.setData({
            page: ++this.data.page
          })
          this.getList()
        }
      },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})